package com.wc.blue_bridge_history.JavaLast.C_鸡哥的蛋糕大作战;

import java.util.Scanner;

/**
 * @Author congge
 * @Date 2024/4/7 16:41
 * @description https://www.lanqiao.cn/paper/3998/problem/4145/
 */
public class Main {
    static int[] a = new int[]{1, 0, 0, 0, 0, 0, 1, 0, 2, 1};

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a, b;
        a = sc.nextInt();
        b = sc.nextInt();
        int maxV = 0;
        int num = a;
        for (int i = a; i <= b; i++) {
            int cur = work(i);
            if (cur > maxV) {
                maxV = cur;
                num = i;
            }
        }
        System.out.println(num);
    }

    static int work(int num) {
        if (num == 0) return a[0];
        int res = 0;
        while (num > 0) {
            res += a[num % 10];
            num /= 10;
        }
        return res;
    }
}
